package com.ruoyi.sl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sl.domain.SlDm;
import com.ruoyi.sl.service.ISlDmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报工项扣款Controller
 * 
 * @author admin
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/sl/dm")
public class SlDmController extends BaseController
{
    @Autowired
    private ISlDmService slDmService;

    /**
     * 查询报工项扣款列表
     */
    @PreAuthorize("@ss.hasPermi('sl:dm:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlDm slDm)
    {
        startPage();
        List<SlDm> list = slDmService.selectSlDmList(slDm);
        return getDataTable(list);
    }

    /**
     * 导出报工项扣款列表
     */
    @PreAuthorize("@ss.hasPermi('sl:dm:export')")
    @Log(title = "报工项扣款", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlDm slDm)
    {
        List<SlDm> list = slDmService.selectSlDmList(slDm);
        ExcelUtil<SlDm> util = new ExcelUtil<SlDm>(SlDm.class);
        util.exportExcel(response, list, "报工项扣款数据");
    }

    /**
     * 获取报工项扣款详细信息
     */
    @PreAuthorize("@ss.hasPermi('sl:dm:query')")
    @GetMapping(value = "/{dmId}")
    public AjaxResult getInfo(@PathVariable("dmId") Long dmId)
    {
        return success(slDmService.selectSlDmByDmId(dmId));
    }

    /**
     * 新增报工项扣款
     */
    @PreAuthorize("@ss.hasPermi('sl:dm:add')")
    @Log(title = "报工项扣款", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlDm slDm)
    {
        return toAjax(slDmService.insertSlDm(slDm));
    }

    /**
     * 修改报工项扣款
     */
    @PreAuthorize("@ss.hasPermi('sl:dm:edit')")
    @Log(title = "报工项扣款", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlDm slDm)
    {
        return toAjax(slDmService.updateSlDm(slDm));
    }

    /**
     * 删除报工项扣款
     */
    @PreAuthorize("@ss.hasPermi('sl:dm:remove')")
    @Log(title = "报工项扣款", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dmIds}")
    public AjaxResult remove(@PathVariable Long[] dmIds)
    {
        return toAjax(slDmService.deleteSlDmByDmIds(dmIds));
    }
}
